<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "shbb_batch".
 *
 * @property integer $id
 * @property integer $park_id
 * @property string $code
 * @property integer $product_id
 * @property integer $trace_type_id
 * @property integer $build_time
 * @property integer $build_account_id
 * @property integer $audit_time
 * @property integer $audit_account_id
 * @property integer $start_time
 * @property integer $finish_time
 * @property integer $state
 * @property string $td_img
 * @property string $bar_img
 * @property integer $market_time
 * @property string $comment
 *
 * @property ShbbPark $park
 * @property User $buildAccount
 * @property User $auditAccount
 * @property ShbbTraceType $traceType
 * @property ShbbBatchDetail[] $shbbBatchDetails
 * @property ShbbTraceGrowthPic[] $shbbTraceGrowthPics
 * @property ShbbTraceGrowthVideo[] $shbbTraceGrowthVideos
 * @property ShbbTraceManure[] $shbbTraceManures
 * @property ShbbTracePesticide[] $shbbTracePesticides
 */
class Batch extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shbb_batch';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['park_id', 'product_id', 'trace_type_id', 'build_time', 'build_account_id', 'audit_time', 'audit_account_id', 'start_time', 'finish_time', 'state', 'market_time'], 'integer'],
            [['comment'], 'string'],
            [['code', 'td_img', 'bar_img'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'park_id' => 'Park ID',
            'code' => 'Code',
            'product_id' => 'Product ID',
            'trace_type_id' => 'Trace Type ID',
            'build_time' => 'Build Time',
            'build_account_id' => 'Build Account ID',
            'audit_time' => 'Audit Time',
            'audit_account_id' => 'Audit Account ID',
            'start_time' => 'Start Time',
            'finish_time' => 'Finish Time',
            'state' => 'State',
            'td_img' => 'Td Img',
            'bar_img' => 'Bar Img',
            'market_time' => 'Market Time',
            'comment' => 'Comment',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPark()
    {
        return $this->hasOne(ShbbPark::className(), ['id' => 'park_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBuildAccount()
    {
        return $this->hasOne(User::className(), ['id' => 'build_account_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAuditAccount()
    {
        return $this->hasOne(User::className(), ['id' => 'audit_account_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTraceType()
    {
        return $this->hasOne(ShbbTraceType::className(), ['id' => 'trace_type_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbBatchDetails()
    {
        return $this->hasMany(ShbbBatchDetail::className(), ['batch_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbTraceGrowthPics()
    {
        return $this->hasMany(ShbbTraceGrowthPic::className(), ['batch_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbTraceGrowthVideos()
    {
        return $this->hasMany(ShbbTraceGrowthVideo::className(), ['batch_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbTraceManures()
    {
        return $this->hasMany(ShbbTraceManure::className(), ['batch_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbTracePesticides()
    {
        return $this->hasMany(ShbbTracePesticide::className(), ['batch_id' => 'id']);
    }
}
